<template>
  <a-modal
    title="状态快捷修改"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel"
    cancelText="关闭"
    style="top:20px;"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="预告商品">
          <j-dict-select-tag v-decorator="[ 'previewStatus', {}]" placeholder="是否为预告商品：0->不是；1->是" :type="'radio'" :triggerChange="true" dictCode="yn"/>
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="新品">
          <j-dict-select-tag v-decorator="[ 'newStatus', {}]" placeholder="新品状态:0->不是新品；1->新品" :type="'radio'" :triggerChange="true" dictCode="yn"/>
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="推荐">
          <j-dict-select-tag v-decorator="[ 'recommandStatus', {}]"  placeholder="推荐状态；0->不推荐；1->推荐" :type="'radio'" :triggerChange="true" dictCode="yn"/>
        </a-form-item>
        <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="热门">
          <j-dict-select-tag v-decorator="[ 'hotStatus', {}]"  placeholder="热门状态；0->不热门；1->热门" :type="'radio'" :triggerChange="true" dictCode="yn"/>
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import pick from 'lodash.pick'
  import { httpAction } from '@/api/manage'

  export default {
    name: "PmsProductStatusModal",
    data () {
      return {
        visible: false,
        confirmLoading: false,
        model: {},

        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        form:this.$form.createForm(this),
        url: {
          edit: "/pms/pmsProduct/editProductStatus"
        },
      }
    },
    created () {
      console.log("created");
    },
    methods: {
      show(record) {
        //this.form.resetFields();
        this.visible = true;
        this.model = record;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'previewStatus','newStatus','recommandStatus','hotStatus'))
        });
      },
      close () {
        this.form.resetFields();
        this.$emit('close');
        this.visible = false;
      },
      handleSubmit () {
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            console.log(values)
            this.confirmLoading = true;
            let formData = Object.assign({}, values);
            formData.id = this.model.id;
            console.log(formData)
            httpAction(this.url.edit,formData,'put').then((res)=>{
              if(res.success){
                this.$message.success(res.message);
                this.$emit('ok');
              }else{
                this.$message.warning(res.message);
              }
            }).finally(() => {
              this.confirmLoading = false;
              this.close();
            })
          }
        })
      },
      handleCancel () {
        this.close()
      },
    }
  }
</script>